bitkeeper revision 1.622 (3fbd4bebsTJdb-aVkXDUuIpXoNZ5DA)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 20 Nov 2003 23:19:07 +0000 (23:19 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 20 Nov 2003 23:19:07 +0000 (23:19 +0000)
setup.py, Makefile:
  A XenoUtil module containing handy helpers for creating control scripts.
XenoUtil.py:
  new file

.rootkeys
tools/xc/py/Makefile
tools/xc/py/XenoUtil.py [new file with mode: 0644]
tools/xc/py/setup.py

index 26dfc3af65cbac38976653310e1edca385f13690..f97a84886244085a7079f87a8d2727fc9cf4f854 100644 (file)
--- a/.rootkeys
+++ b/.rootkeys
 3fbba6dc1uU7U3IFeF6A-XEOYF2MkQ tools/xc/lib/rpm.spec
 3fbba6dcrNxtygEcgJYAJJ1gCQqfsA tools/xc/lib/xc.h
 3fbd0a3dTwnDcfdw0-v46dPbX98zDw tools/xc/py/Makefile
+3fbd4bd6GtGwZGxYUJPOheYIR7bPaA tools/xc/py/XenoUtil.py
 3fbd0a40yT6G3M9hMpaz5xTUdl0E4g tools/xc/py/setup.py
 3fbd0a42l40lM0IICw2jXbQBVZSdZg tools/xc/py/xc_py.c
 3f72f1bdJPsV3JCnBqs9ddL9tr6D2g xen/COPYING
index 2357d11ccba7f46152fad5d2ac04da601118efb0..a402cf77b6a36628e85cadfb7a4881ebddc950d8 100644 (file)
@@ -6,4 +6,4 @@ install:
        python setup.py install
 
 clean:
-       rm -rf build
+       rm -rf build *.pyc *.pyo *.o *.a *~
diff --git a/tools/xc/py/XenoUtil.py b/tools/xc/py/XenoUtil.py
new file mode 100644 (file)
index 0000000..f9b8728
--- /dev/null
@@ -0,0 +1,66 @@
+
+import string, re, os
+
+def blkdev_name_to_number(name):
+    """Take the given textual block-device name (e.g., '/dev/sda1',
+    'hda') and return the device number used by the OS. """
+
+    if not re.match( '/dev/', name ):
+        name = '/dev/' + name
+        
+    fd = os.popen( '/bin/ls -lL ' + name + ' 2>/dev/null' )
+    line = fd.readline()
+
+    #brw-rw----    1 root     mail       8,   3 Aug 30  2001 /dev/sda3
+    m = re.search( '^b\S+\s+\d+\s+\S+\s+\S+\s+(\d+),\s+(\d+)\s+\S+\s+\d+' +
+                   '\s+\d+\s+' + name + '$', line )
+
+    if m:
+        # hack -- we just assume device minors are 8 bits
+        return (string.atol(m.group(1)) << 8) + string.atol(m.group(2))
+    return None
+
+
+# lookup_blkdev_partn_info( '/dev/sda3' )
+def lookup_blkdev_partn_info(partition):
+    """Take the given block-device name (e.g., '/dev/sda1', 'hda')
+    and return a information tuple ( partn-dev, disc-dev, start-sect,
+    nr-sects, type )
+        partn-dev:  Device number of the given partition
+        disc-dev:   Device number of the disc containing the partition
+        start-sect: Index of first sector of the partition
+        nr-sects:   Number of sectors comprising this partition
+        type:       'Disk' or identifying name for partition type
+    """
+
+    if not re.match( '/dev/', partition ):
+        partition = '/dev/' + partition
+
+    drive = re.split( '[0-9]', partition )[0]
+
+    if drive == partition:
+        fd = os.popen( '/sbin/sfdisk -s ' + drive + ' 2>/dev/null' )
+        line = fd.readline()
+        if line:
+            return ( blkdev_name_to_number(drive),
+                     blkdev_name_to_number(drive),
+                     0,
+                     string.atol(line) * 2,
+                     'Disk' )
+        return None
+
+    # determine position on disk
+    fd = os.popen( '/sbin/sfdisk -d ' + drive + ' 2>/dev/null' )
+
+    #['/dev/sda3 : start= 16948575, size=16836120, Id=83, bootable\012']
+    lines = fd.readlines()
+    for line in lines:
+        m = re.search( '^' + partition + '\s*: start=\s*([0-9]+), ' +
+                       'size=\s*([0-9]+), Id=\s*(\S+).*$', line)
+        if m:
+            return ( blkdev_name_to_number(partition),
+                     blkdev_name_to_number(drive),
+                     string.atol(m.group(1)),
+                     string.atol(m.group(2)),
+                     m.group(3) )
+    return None
index 59096039fa616c28c71ee598de7d8d96236dfc80..8da21e5c613994896e3404928187f15d34a6aaef 100644 (file)
@@ -14,3 +14,5 @@ module.extra_objects = ["../lib/libxc.a"]
 module.libraries     = ["z"]
 
 setup(name = "Xc", version = "1.0", ext_modules = [module])
+
+setup(name = "XenoUtil", version = "1.0", py_modules = ["XenoUtil"])